package com.reremouse.rerebbs.model;

import com.reremouse.ejb.impl.IPSeekerService;
import com.reremouse.rerebbs.dao.IBbsFileDAO;
import com.reremouse.rerebbs.dao.IBbsMessageDAO;
import com.reremouse.rerebbs.dao.IBbsTalkDAO;
import com.reremouse.rerebbs.dao.IBbsThreadDAO;
import com.reremouse.util.SpringHelper;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
@Table(name = "rerebbs_user")
public class BbsUser
        implements Serializable {
    @Id
    @Column(name = "id", unique = true, nullable = false)
    private Long id = Long.valueOf(System.nanoTime());
    @Column(name = "username")
    private String username;
    @Column(name = "password")
    private String password;
    @Column(name = "email")
    private String email;
    @Column(name = "tel")
    private String tel;
    @Column(name = "reg_ip")
    private String regIp;
    @Column(name = "last_ip")
    private String lastIp;
    @Column(name = "reg_time", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date regTime = new Date();
    @Column(name = "birth_day", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date birthDay = new Date();
    @Column(name = "last_time", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastTime = new Date();
    @Column(name = "name")
    private String name;
    @Column(name = "gender")
    private String gender = "man";
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "province")
    private DictProvince province;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "city")
    private DictCity city;
    @Column(name = "id_num")
    private String idNum;
    @Column(name = "activated")
    private Boolean activated = Boolean.valueOf(true);
    @Column(name = "enabled")
    private Boolean enabled = Boolean.valueOf(true);
    @Column(name = "pid")
    private String pid;
    @Column(name = "group1")
    private String group1;
    @ManyToMany(cascade = {javax.persistence.CascadeType.MERGE}, fetch = FetchType.LAZY)
    @JoinTable(name = "rerebbs_zonemag", joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "zone_id", referencedColumnName = "id")})
    List<BbsZone> managedZone;
    @OneToMany(mappedBy = "genBy", cascade = {javax.persistence.CascadeType.MERGE}, fetch = FetchType.LAZY)
    List<BbsThread> threads;
    @OneToMany(mappedBy = "genBy", cascade = {javax.persistence.CascadeType.MERGE}, fetch = FetchType.LAZY)
    List<BbsThread> talks;
    @Transient
    private Integer threadCount;
    @Transient
    private Integer talkCount;
    @Transient
    private Integer age;
    @Column(name = "score")
    private long score = 10L;
    @Column(name = "mark_del")
    private boolean markDel;
    @Column(name = "address")
    private String address;
    @Column(name = "total_length")
    long totalLength;
    @Column(name = "qq")
    private String qq;
    @Column(name = "pic_url")
    private String picUrl = "";
    @ManyToMany(mappedBy = "managers", fetch = FetchType.EAGER)
    private List<BbsZone> managedZones;
    @Transient
    private String regIpAddr;
    @Transient
    private String lastIpAddr;
    @Transient
    private long unReadedMsgNum;
    @Transient
    double realLength;

    public BbsUser() {
    }

    public BbsUser(Timestamp regTime) {
        this.regTime = regTime;
    }

    public BbsUser(String username, String password, String email, String tel, String regIp, String lastIp, Timestamp regTime, String name, String gender, Integer age, String idNum, Boolean activated, Boolean enabled) {
        this.username = username;
        this.password = password;
        this.email = email;
        this.tel = tel;
        this.regIp = regIp;
        this.lastIp = lastIp;
        this.regTime = regTime;
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.idNum = idNum;
        this.activated = activated;
        this.enabled = enabled;
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getTel() {
        return this.tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String getRegIp() {
        return this.regIp;
    }

    public void setRegIp(String regIp) {
        this.regIp = regIp;
    }

    public String getLastIp() {
        return this.lastIp;
    }

    public void setLastIp(String lastIp) {
        this.lastIp = lastIp;
    }

    public Date getRegTime() {
        return this.regTime;
    }

    public void setRegTime(Date regTime) {
        this.regTime = regTime;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return this.gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Integer getAge() {
        this.age = Integer.valueOf(new Date().getYear() - this.birthDay.getYear());
        return this.age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getIdNum() {
        return this.idNum;
    }

    public void setIdNum(String idNum) {
        this.idNum = idNum;
    }

    public Boolean getActivated() {
        return this.activated;
    }

    public void setActivated(Boolean activated) {
        this.activated = activated;
    }

    public Boolean getEnabled() {
        return this.enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public Integer getThreadCount() {
        IBbsThreadDAO tDAO = (IBbsThreadDAO) SpringHelper.getSpringBean("SxbbsThreadDAO");
        this.threadCount = Integer.valueOf(tDAO.findByGenBy(this, new int[]{0, 9999999}).size());
        return this.threadCount;
    }

    public void setThreadCount(Integer threadCount) {
        this.threadCount = threadCount;
    }

    public Integer getTalkCount() {
        IBbsTalkDAO talkDAO = (IBbsTalkDAO) SpringHelper.getSpringBean("BbsTalkDAO");
        this.talkCount = Integer.valueOf(talkDAO.findByGenBy(this, new int[]{0, 9999999}).size());
        return this.talkCount;
    }

    public void setTalkCount(Integer talkCount) {
        this.talkCount = talkCount;
    }

    public long getScore() {
        return this.score;
    }

    public void setScore(long score) {
        this.score = score;
    }

    public boolean isMarkDel() {
        return this.markDel;
    }

    public void setMarkDel(boolean markDel) {
        this.markDel = markDel;
    }

    public Date getBirthDay() {
        return this.birthDay;
    }

    public void setBirthDay(Date birthDay) {
        this.birthDay = birthDay;
    }

    public List<BbsZone> getManagedZones() {
        return this.managedZones;
    }

    public void setManagedZones(List<BbsZone> managedZones) {
        this.managedZones = managedZones;
    }

    public String getRegIpAddr() {
        IPSeekerService ips = (IPSeekerService) SpringHelper.getSpringBean("ipSeekerService");
        if (this.regIp != null) {
            this.regIpAddr = ips.seek(this.regIp);
        }
        return this.regIpAddr;
    }

    public void setRegIpAddr(String ipAddr) {
        this.regIpAddr = ipAddr;
    }

    public String getLastIpAddr() {
        IPSeekerService ips = (IPSeekerService) SpringHelper.getSpringBean("ipSeekerService");
        if (this.lastIp != null) {
            this.lastIpAddr = ips.seek(this.lastIp);
        }
        return this.lastIpAddr;
    }

    public void setLastIpAddr(String lastIpAddr) {
        this.lastIpAddr = lastIpAddr;
    }

    public long getUnReadedMsgNum() {
        IBbsMessageDAO ips = (IBbsMessageDAO) SpringHelper.getSpringBean("BbsMessageDAO");
        this.unReadedMsgNum = ips.getUnReadedMsgNumByReceiver(this.id.longValue());
        return this.unReadedMsgNum;
    }

    public void setUnReadedMsgNum(long unReadedMsgNum) {
        this.unReadedMsgNum = unReadedMsgNum;
    }

    public DictCity getCity() {
        return this.city;
    }

    public void setCity(DictCity city) {
        this.city = city;
    }

    public DictProvince getProvince() {
        return this.province;
    }

    public void setProvince(DictProvince province) {
        this.province = province;
    }

    public String getAddress() {
        return this.address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public long getTotalLength() {
        return this.totalLength;
    }

    public void setTotalLength(long totalLength) {
        this.totalLength = totalLength;
    }

    public double getRealLength() {
        IBbsFileDAO cfDAO = (IBbsFileDAO) SpringHelper.getSpringBean("BbsFileDAO");
        List<BbsFileModel> cfs = cfDAO.findAllClientFileByUsr(this.id.longValue());
        double len = 0.0D;
        for (BbsFileModel f : cfs) {
            len += f.getRealLength();
        }
        len = len / 1024.0D / 1024.0D;
        this.realLength = len;
        return this.realLength;
    }

    public void setRealLength(double realLength) {
        this.realLength = realLength;
    }

    public String getQq() {
        return this.qq;
    }

    public void setQq(String qq) {
        this.qq = qq;
    }

    public String getPicUrl() {
        return this.picUrl;
    }

    public void setPicUrl(String picUrl) {
        this.picUrl = picUrl;
    }

    public Date getLastTime() {
        return this.lastTime;
    }

    public void setLastTime(Date lastTime) {
        this.lastTime = lastTime;
    }

    public List<BbsZone> getManagedZone() {
        return this.managedZone;
    }

    public void setManagedZone(List<BbsZone> managedZone) {
        this.managedZone = managedZone;
    }

    public List<BbsThread> getThreads() {
        return this.threads;
    }

    public void setThreads(List<BbsThread> threads) {
        this.threads = threads;
    }

    public List<BbsThread> getTalks() {
        return this.talks;
    }

    public void setTalks(List<BbsThread> talks) {
        this.talks = talks;
    }

    public String getPid() {
        return this.pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public String getGroup1() {
        return this.group1;
    }

    public void setGroup1(String group1) {
        this.group1 = group1;
    }
}



/* Location:           F:\jsp源码\蝙蝠论坛系统\rerebbs\WEB-INF\classes\

 * Qualified Name:     com.reremouse.rerebbs.model.BbsUser

 * JD-Core Version:    0.7.0.1

 */